package org.prosim.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class BaseAction extends ActionSupport implements ServletRequestAware,
		ServletResponseAware, SessionAware {
	
	public static final String RELOAD = "reload";
	
	protected HttpServletRequest request;
	protected HttpServletResponse response;
	protected Map<String, Object> session;

	@Override
	public void setSession(Map<String, Object> sessionMap) {
		this.session = sessionMap;
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}
	
	
	protected void ctxAttribute(String key, Object value) {
		request.setAttribute(key, value);
	}

	
	/**
	 * show error message
	 * 
	 * @param error
	 */
	protected void addErrorMessage(String error) {
		ctxAttribute("_error", error);
	}
	
	
	/**
	 * show warn message
	 * 
	 * @param warn
	 */
	protected void addWarnMessage(String warn) {
		ctxAttribute("_warn", warn);
	}
	
	/**
	 * show message
	 * 
	 * @param error
	 */
	protected void addMessage(String info) {
		ctxAttribute("_info", info);
	}
	
	/**
	 * show success message
	 * 
	 * @param error
	 */
	protected void addSuccessMessage(String success) {
		ctxAttribute("_success", success);
	}
}
